#include <bits/stdc++.h>
using namespace std;

int a[2005];
int ans = 0,n;

void dfs(int dep,int lst0,int lst1,int sum)
{
	if (dep > n)
	{
		ans = max(ans,sum);
		return;
	}
	dfs(dep + 1,dep,lst1,sum + (a[dep] == a[lst0]) * a[dep]);
	dfs(dep + 1,lst0,dep,sum + (a[dep] == a[lst1]) * a[dep]);
	return;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin >> t;
	for (;t > 0;t--)
	{
		cin >> n;
		for (int i = 1;i <= n;i++)
			cin >> a[i];
		ans = 0;
		dfs(1,0,0,0);
		cout << ans << endl;
	}
	return 0;
}
